package milu.dbxml.request;

import milu.dbxml.DbXmlContext;

import com.sleepycat.dbxml.XmlContainer;
import com.sleepycat.dbxml.XmlDocument;
import com.sleepycat.dbxml.XmlDocumentConfig;
import com.sleepycat.dbxml.XmlException;
import com.sleepycat.dbxml.XmlManager;

public class PutDocument extends TransactionalUpdate {
	private XmlDocument doc;
	private XmlDocumentConfig xdc;
	private String content;

	public PutDocument(DbXmlContext dbxml, XmlDocument doc, XmlDocumentConfig xdc) {
		super(dbxml);
		this.doc = doc;
		this.xdc = xdc;
	}

	public PutDocument(DbXmlContext dbxml, String content, XmlDocumentConfig xdc) {
		super(dbxml);
		this.content = content;
		this.xdc = xdc;
	}

	@Override public void perform() throws XmlException {
		XmlManager mgr = this.dbxml.getManager();
		if (null == doc) {
			this.doc = mgr.createDocument();
			this.doc.setContent(content);
		}
		XmlContainer cont = dbxml.getContainer();
		cont.putDocument(getTransaction(), doc, xdc);
	}

}
